class Rect extends egret.Sprite
{
    public constructor()
    {
        super();//继承超级方法
        this.touchEnabled = true;//打开点击事件
        this.darw();//绘图
    }

    private _colors:Array<number> = [0x000000,0xffffff,0xff0000,0x0000ff];//颜色值数组
    private _currentColor:number = 1;//数组下标，默认1

    private darw()
    {
        this.width = Data.getRectWidth();
        this.height = Data.getRectWidth();
        this.graphics.lineStyle(1,0x000000);
        this.graphics.beginFill(this._colors[this._currentColor]);
        this.graphics.drawRect(0,0,100,100);
        this.graphics.endFill();
    }

    private _type:string = RectType.NOCLICKABLE; 
    public get type():string
    {//获取当前点击类型
        return this._type;
    }
    public set type(val:string)
    {//修改当前点击类型
        if(val != this._type)
        {
            this._type = val;//类型赋值
            if(this._type == RectType.CLICKABLE)//根据类型切换数组下标的颜色值
            {
                this._currentColor = 0;
            }
            else
            {
                this._currentColor = 1;
            }
            this.darw();//重新绘制
        }
    }
    public onRectClick()//点击后的颜色设置
    {
        if(this._type == RectType.CLICKABLE)//根据类型切换数组下标的颜色值
        {
            this._currentColor = 3;
        }
        else
        {
            this._currentColor = 2;
        }
        this.darw();//重新绘制
    }

}